const express = require('express');
const router = express.Router();
const adminBorrowController = require('../controllers/adminBorrowController');
const { authenticateAdmin } = require('../middleware/auth');
const { adminLogger } = require('../middleware/adminLogger');

// 所有路由都需要管理员权限
router.use(authenticateAdmin);

// 获取所有借阅记录
router.get('/records', adminBorrowController.getAllBorrowRecords);

// 获取借阅统计
router.get('/stats', adminBorrowController.getAdminBorrowStats);

// 获取逾期记录
router.get('/overdue', adminBorrowController.getAdminOverdueRecords);

// 管理员办理借阅
router.post(
  '/borrow',
  adminLogger('admin_borrow', (req) => `办理借阅: 用户ID ${req.body.userId}, 图书ID ${req.body.bookId}`),
  adminBorrowController.adminBorrowBook
);

// 管理员办理归还
router.post(
  '/return',
  adminLogger('admin_return', (req) => `办理归还: 借阅记录ID ${req.body.borrowId}`),
  adminBorrowController.adminReturnBook
);

// 快速借阅（通过手机号和ISBN）
router.post(
  '/quick-borrow',
  adminLogger('quick_borrow', (req) => `快速借阅: ${req.body.phone} - ISBN ${req.body.isbn}`),
  adminBorrowController.quickBorrow
);

module.exports = router;

